<template>
  <BasicModal v-bind="$attrs" @register="userRegister" :title="getTitle" width="900px" @ok="submitAudit">
    <BasicTable @register="registerUserTable" :loading="loading" :pagination="{ pageSize: 15 }" :rowSelection="{ type: 'radio' }"> </BasicTable>
  </BasicModal>
</template>

<script lang="ts" setup>
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { ref, reactive } from 'vue';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { getUserList } from './LabItemReportList.api';
  import { labUserColumns } from './LabItemReportList.data';
  import { BasicTable } from '/@/components/Table';
  import { FormSchema } from '/@/components/Table';

  const loading = ref(false);
  const getTitle = ref('人员信息');
  const queryParam = reactive<any>({});

  const formPerData = reactive<Record<string, any>>({
    oper: '',
  });

  const emits = defineEmits<{
    (event: 'getRatifyResult', uId: String, uName: String): void;
    (event: 'getAuditResult', uId: String, uName: String): void;
  }>();

  const [userRegister, { setModalProps, closeModal }] = useModalInner(async (data) => {
    setModalProps({
      minHeight: 180,
    });
    loading.value = true;
    formPerData.oper = data.oper;
    console.log(formPerData.oper);
  });

  const searchFormSchema: FormSchema[] = [
    {
      label: '姓名',
      field: 'realname',
      component: 'JInput',
      colProps: { span: 8 },
    },
  ];

  // 注册table数据
  const { tableContext } = useListPage({
    tableProps: {
      api: getUserList,
      columns: labUserColumns,
      canResize: false,
      //   useSearchForm: false,
      formConfig: {
        // labelWidth: 200,
        schemas: searchFormSchema,
      },
      showIndexColumn: true,
      showTableSetting: false,
      showActionColumn: false,
      beforeFetch: (params) => {
        return Object.assign(params, queryParam);
      },
    },
  });

  const [registerUserTable, { getSelectRows }] = tableContext;

  async function submitAudit() {
    const selectedRows = getSelectRows()[0];
    const id = selectedRows['id'];
    const realname = selectedRows['realname'];
    closeModal();
    if (formPerData.oper == 'ratify') {
      console.log(formPerData.oper);
      emits('getRatifyResult', id, realname);
    } else {
      console.log(formPerData.oper);
      emits('getAuditResult', id, realname);
    }
  }
</script>
<style scoped lang="less">
  ::v-deep .jeecg-basic-form .ant-form-item-label > label {
    font-size: 14px;
  }
  ::v-deep .jeecg-basic-form .ant-input {
    font-size: 14px;
  }
</style>
